
<template>
<div>
  <el-dialog
      title="添加园区"
      :visible.sync="dialogVisible"
      width="30%"
  >
  <span> <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="园区名称">
      <el-input v-model="form.name"></el-input>
    </el-form-item>
    <el-form-item label="园区地址">
      <el-input v-model="form.address"></el-input>
    </el-form-item>
  </el-form></span>
    <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="submit">确 定</el-button>
  </span>
  </el-dialog>
</div>
</template>
<script>
import {_areaAdd} from '../../../../api/super_admin'

export default {
  name: 'AreaAddDialog',
  data () {
    return {
      dialogVisible: false,
      form: {
        name: '',
        address: ''
      }
    }
  },
  methods: {
    show () {
      this.dialogVisible = true
    },
    submit () {
      for (let item in this.form) {
        if (item === '') {
          this.$message({
            message: '所有字段非空',
            type: 'error'
          })
          return
        }
      }
      this.$confirm('确定添加园区？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        _areaAdd(this.form).then(res => {
          if (res.status) {
            this.$message({
              message: '添加成功',
              type: 'success'
            })
            this.$emit('ok')
            this.dialogVisible = false
          } else {
            this.$message({
              message: res.message,
              type: 'error'
            })
          }
        })
      }).catch()
    }
  }
}
</script>

<style scoped>

</style>
